package org.vacoor.xqq.core.bean;

/**
 * Created with IntelliJ IDEA.
 * User: vacoor
 * Date: 10/23/13
 * Time: 11:56 AM
 * To change this template use File | Settings | File Templates.
 */
public enum AuthcState {
    SUCCESS(0, "登录成功"),
    INVALID_ACCOUNT(3, "您输入的帐号或密码不正确，请重新输入。"),
    INVALID_CAPTCHA(4, "您输入的验证码不正确，请重新输入。"),
    NETWORK_ERROR(7, "很遗憾，网络连接出现异常，请您稍后再试。"),
    UNKNOWN_ERROR(-1 << 3, "未知错误");

    private final String msg;
    private final int code;

    AuthcState(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getMsg() {
        return msg;
    }

    public int getCode() {
        return code;
    }

    public static AuthcState fromCode(int code) {
        switch (code) {
            case 0:
                return SUCCESS;
            case 3:
                return INVALID_ACCOUNT;
            case 4:
                return INVALID_CAPTCHA;
            case 7:
                return NETWORK_ERROR;
            default:
                return UNKNOWN_ERROR;
        }
    }
}
